package kr.co.bettersoft.waitnumberstoret.activity;

import kr.co.bettersoft.waitnumberstoret.common.CommonConstant;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 첫화면. 로그인할지, 가입할지 선택하는 화면이다. (버튼 2개만 있음)
 *  가입버튼 누르면 가입페이지로, 로그인 버튼 누르면 로그인페이지로 이동
 * @author blue
 *
 */
public class LoginRegisterChoiceActivity extends Activity{
	/////////////////////////////////////////////////////////////////////////////////////////////////////
	// 변수

	String TAG = "LoginRegisterChoiceActivity";


	// 전달받은 값
	Intent receivedIntent;
	String runMode = "";
	static String receivedChatRoomId = "";
	static String receivedChatRoomOwner = "";
	static String receivedUserId = "";

	SharedPreferences sharedPrefCustom;	// 공용 프립스	

	// 화면 구성 					 
	Button registerActivityBtn;		//	 등록 버튼		
	Button loginActivityBtn;		//	 로그인버튼

	ProgressBar pb1;		// 중단 로딩 진행바

	///////////////////////////////////////////////////////////////////////////////////////////////////////////////	

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login_register_choice_activity);

		// 프립
		sharedPrefCustom = getSharedPreferences(CommonConstant.prefName,
				Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE);

		// 전달 받은 값
		receivedIntent = getIntent();
		runMode = receivedIntent.getStringExtra("RunMode");
		receivedChatRoomId = receivedIntent.getStringExtra("chatRoomId");
		receivedChatRoomOwner = receivedIntent.getStringExtra("chatRoomOwner");
		receivedUserId = receivedIntent.getStringExtra("userId");
		if(runMode==null){
			runMode = "";
		}
		if(receivedChatRoomId==null){
			receivedChatRoomId = "";
		}
		if(receivedChatRoomOwner==null){
			receivedChatRoomOwner = "";
		}
		if(receivedUserId==null){
			receivedUserId = "";
		}

		// 레이아웃의 개체들을 가져와서 사용
		registerActivityBtn = (Button) findViewById(R.id.register_activity_btn);
		loginActivityBtn = (Button) findViewById(R.id.login_activity_btn);


		// 버튼  리스너.
		registerActivityBtn.setOnClickListener(new OnClickListener() {			 
			@Override
			public void onClick(View v) {
				Log.w(TAG,"registerActivityBtn click");
				Intent webIntent = new Intent(LoginRegisterChoiceActivity.this, MyWebViewActivity.class);
				webIntent.putExtra("loadingURL", CommonConstant.merchantRegisterURL);
				startActivity(webIntent);
				
//				Intent i = new Intent(returnThis(), RegisterMemberActivity.class);
//				startActivity(i);
//				finish();
			}
		});
		loginActivityBtn.setOnClickListener(new OnClickListener() {			 
			@Override
			public void onClick(View v) {
				Log.w(TAG,"loginActivityBtn click");
				Intent i = new Intent(returnThis(), LoginActivity.class);
				startActivity(i);
				finish();
			}
		});
	}

	/////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// 유틸	

	/**
	 * returnThis
	 *  컨택스트 반환한다
	 *
	 * @param
	 * @param
	 * @return
	 */
	public Context returnThis(){
		return this;
	}

	/**
	 * onBackPressed
	 *  종료시 모두 종료시킨다. (홈갔다왔을때 용도)
	 *
	 * @param
	 * @param
	 * @return
	 */
	@Override
	public void onBackPressed() {
		SharedPreferences.Editor appRunningYnPref = sharedPrefCustom.edit();
		appRunningYnPref.putBoolean("appRunningYn", false);		// 실행중 아님.
		appRunningYnPref.commit();
		android.os.Process.killProcess(android.os.Process.myPid());
		//			finish();
		super.onBackPressed();
	}

}
